
/* 记分牌类 */
class ScorePanel {
    score:number = 0
    level:number = 1
    scoreElement:HTMLElement
    scoreLevelElement:HTMLElement
    // 设置一个变量来限制等级最大
    maxLevel:number
    upScore:number //多少分时候升一级
    constructor(maxLevel:number = 10,upScore:number = 10){
        this.maxLevel = maxLevel
        this.upScore = upScore
        this.scoreElement = document.querySelector('#score') as HTMLElement
        this.scoreLevelElement = document.querySelector('#level') as HTMLElement
    }
    addScore(){
        this.score++;
        this.scoreElement.innerText = this.score + '';
        // 每加10分会升级
        if(this.score % this.upScore === 0) {
            this.levelUp();
        }
    }

    // 等级提升 等级需要有一个上限
    levelUp(){
        if(this.level < this.maxLevel){
            this.level++;
            this.scoreLevelElement.innerText = this.level + '';
        }
    }
}

export default ScorePanel